<template>
  <a-modal title='金额抵扣选择(可通过双击行选择)' :width='1000'  :dialog-style="{ top: '10px' }" :visible='visible' :confirmLoading='loading' @ok='handleSubmit' @cancel='handleCancel'>
    <f-table ref='table' rowKey='saleManBalanceId' v-if='visible' @dblclick='dblclick' :columns='columns' :multiple='false' :showRadio='true' :operator='operator' :params='queryParam' :api='api.bsmb' handler='saleManBalancePageListHandler' @onSelectChange='onSelectChange'>
       <span slot='action' slot-scope='text, record'>
         <template>
          <a @click='openCfAmountModal(record)' v-if='!record.parentId'>拆分</a>
          <a href='javascript:;' @click='revokeCfAmount(record)' v-if='record.parentId && !record.orderDetailsId'>撤销拆分</a>
        </template>
      </span>
    </f-table>
    <a-modal title='拆分金额' v-model='chaifenModal' width='800px' height='500px' @cancel='this.chaifenModal=false' @ok='cfSubmit'>
      <f-form ref='cfForm' :action='api.bsmb.cfAmount' v-if='chaifenModal'>
        <f-form-item label='拆分金额' type='number' :precision='2' data-type='number' name='amount' :required='true' />
      </f-form>
    </a-modal>
  </a-modal>
</template>
<script>
import api from "../js/api"

export default {
  name: "SelectSalemanBalanceModal",
  props: {},
  data() {
    let operator = []
    return {
      refs: this.$refs,
      api: Object.assign(api, this.api),
      loading: false,
      visible: false,
      chaifenModal: false,
      selectedRowKeys: [],
      selectedRows: [],
      //列表初始化查询参数
      queryParam: {},
      formItem: {
        saleManBalanceId: null,
        amount: 0
      },
      // 表头
      columns: [
        {
          title: "付款银行",
          align: "center",
          width: "100px",
          dataIndex: "payBankName"
        },
        {
          title: "付款账户",
          align: "center",
          width: "100px",
          dataIndex: "payCardNo"
        },
        {
          title: "资保金金额",
          align: "center",
          width: "100px",
          dataIndex: "amount"
        },
        {
          title: "付款日期",
          align: "center",
          width: "100px",
          dataIndex: "amountDate"
        },
        /*{
          title: "操作",
          align: "center",
          width: "100px",
          scopedSlots: { customRender: "action" }
        }*/
      ],
      operator: operator
    }
  },
  methods: {
    open(params) {
      this.queryParam = params
      this.visible = true
      this.selectedRowKeys = []
      this.selectedRows = []
    },
    close() {
      this.$emit("close")
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    dblclick(record, event) {
      let selectedRowKeys = []
      let selectedRows = []
      selectedRowKeys.push(record.saleManBalanceId)
      selectedRows.push(record)
      this.$emit("onSelectChange", selectedRowKeys, selectedRows)
      this.close()
    },
    //打开拆分金额弹框
    openCfAmountModal(record) {
      this.formItem.saleManBalanceId = record.saleManBalanceId
      this.chaifenModal = true
    },
    //撤销拆分
    revokeCfAmount(params) {
      this.http.confirm(this, {
        content: "确认撤销拆分吗?",
        url: api.bsmb.revokeCfAmount,
        data: {
          saleManBalanceId: params.saleManBalanceId
        },
        success: (me, data) => {
          this.$refs.table.refresh()
        }
      })
    },
    //拆分金额提交
    cfSubmit() {
      this.$refs["cfForm"].submit(this.formItem, () => {
        this.chaifenModal = false
        this.$refs["table"].refresh()
      })
    },
    //商品添加确认
    handleSubmit() {
      this.$emit("onSelectChange", this.selectedRowKeys, this.selectedRows)
      this.close()
    },
    //商品选择回调
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    }
  },
  created() {
  },
  components: {}
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
